package com.xiaobaibai.units;

import com.baomidou.mybatisplus.extension.api.R;
import org.apache.commons.lang3.StringUtils;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class OrderIdUnit {

    private static Random random=new Random();

    public static String createOrderId(Integer userId){
        //生成订单号(28位)
        String stringBuilder = UUID.randomUUID().toString().substring(0, 8) +
                String.valueOf(System.currentTimeMillis()) +
                StringUtils.rightPad(userId.toString(), 6, "0") +
                String.valueOf(random.nextInt(10));
        return stringBuilder;
    }

    public static void main(String[] args) throws InterruptedException {
        String orderId = createOrderId(11);
        System.out.println(orderId);
        String id = UUID.randomUUID().toString().substring(0,8);
        System.out.println(id);
        System.out.println(id.length());
        System.out.println(System.currentTimeMillis());//时间戳13位
        //用户id 6位补全
        //还剩9位UUID前八位+随意一位0~9
//        Random random=new Random();
//        ExecutorService executorService = Executors.newFixedThreadPool(10);
//        for(int i=0;i<10;i++){
//            executorService.execute(()->{
//                for(int j=0;j<10000;j++){
//                    int i1 = random.nextInt(1000);
//                    System.out.println(i1);
//                    if(i1>1000||i1<0)
//                        throw new RuntimeException("1");
//                }
//            });
//        }
//        Thread.sleep(100000);
    }

}
